package com.example.log.impl

import android.util.Log
import com.example.log.ILogger
import com.example.log.LoggerLevel

internal class LogcatImpl : ILogger {
    private var isDebug = true
    private var TAG: String? = ""
    private var level: LoggerLevel? = LoggerLevel.Verbose
    private val loggerFormat = "===> %s -> %s"
    override fun v(tag: String?, log: String?) {
        if (isDebug && level!!.ordinal <= LoggerLevel.Verbose.ordinal) {
            Log.v(TAG, String.format(loggerFormat, tag, log))
        }
    }

    override fun d(tag: String?, log: String?) {
        if (isDebug && level!!.ordinal <= LoggerLevel.Debug.ordinal) {
            Log.d(TAG, String.format(loggerFormat, tag, log))
        }
    }

    override fun i(tag: String?, log: String?) {
        if (isDebug && level!!.ordinal <= LoggerLevel.Info.ordinal) {
            Log.i(TAG, String.format(loggerFormat, tag, log))
        }
    }

    override fun w(tag: String?, log: String?) {
        if (isDebug && level!!.ordinal <= LoggerLevel.Warn.ordinal) {
            Log.w(TAG, String.format(loggerFormat, tag, log))
        }
    }

    override fun e(tag: String?, log: String?) {
        if (isDebug && level!!.ordinal <= LoggerLevel.Error.ordinal) {
            Log.e(TAG, String.format(loggerFormat, tag, log))
        }
    }

    override fun setDebug(_isDebug: Boolean) {
        isDebug = _isDebug
    }

    override fun setLogTag(_tag: String?) {
        TAG = _tag
    }

    override fun setLoggerLevel(_level: LoggerLevel?) {
        level = _level
    }

    override fun setTarget(url: String?) {}
}